home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / FAQs / netfaqs / Xt-faq < prev   
Text File  |  1994-08-01  |  93KB  |  2,255 lines

  1.  
  2. From: ware@cis.ohio-state.edu (Peter Ware)
  3. Newsgroups: comp.windows.x.intrinsics,comp.windows.x,comp.answers,news.answers
  4. Subject: comp.windows.x.intrinsics Frequently Asked Questions (FAQ)
  5. Supersedes: <FAQ-Xt_762643220@oboe.cis.ohio-state.edu>
  6. Followup-To: comp.windows.x.intrinsics
  7. Date: 6 Apr 1994 09:23:20 -0400
  8. Organization: The Ohio State University Dept. of Computer and Info. Science
  9. Lines: 2239
  10. Expires: 18 May 1994 13:23:15 GMT
  11. Reply-To: ware@cis.ohio-state.edu
  12. NNTP-Posting-Host: harmonica.cis.ohio-state.edu
  13. Summary: Answers about the X11 Window System widgets and Xt Intrinsics library
  14. Xref: bloom-beacon.mit.edu comp.windows.x.intrinsics:2472 comp.windows.x:23365 comp.answers:4789 news.answers:17735
  15.  
  16. Archive-name: Xt-FAQ
  17. Version: $Id: FAQ-Xt,v 1.37 1994/04/06 13:22:57 ware Exp $
  18.  
  19.             The X Toolkit Intrinsics F.A.Q
  20.               A monthly posting
  21.  
  22.  
  23. This article contains the answers to some Frequently Asked Questions
  24. (FAQ) from comp.windows.x about the X Toolkit Intrinsics.  To submit
  25. questions (preferably with an answer) send email to:
  26.     ware@cis.ohio-state.edu
  27.  
  28. This FAQ is available on the archive site rtfm.mit.edu in the directory:
  29.  
  30.     pub/usenet/comp.answers
  31.  
  32. The name under which a FAQ is archived appears in the Archive-name
  33. line at the top of the article.  This FAQ is archived as Xt-FAQ.
  34.  
  35. All code fragments are public domain.  
  36.  
  37.                    Contents
  38.  
  39. 0.  Xt Glossary
  40. 1.  Software Versions
  41. 2.  Related FAQ's
  42. 3.  Why does my app core dump when I use signals/alarms/cthreads?
  43. 4.  How do I use a different visual than the default?
  44. 5.  Which visual should an application use?
  45. 6.  Why do only Shell widgets have a Visual?
  46. 7.  Which visual, depth and colormap do Shells inherit?
  47. 8.  I've done all the above and I still get a BadMatch error.  Why?
  48. 9.  Why doesn't my widget get destroyed when I call XtDestroyWidget()?
  49. 10. How do I exit but still execute the DestroyCallbacks?
  50. 11. How do I resize a Shell widget?
  51. 12. Why can't XtAppAddInput() handle files?
  52. 13. What good books and magazines are there on Xt?
  53. 14. What Widgets are available?
  54. 15. What alternatives to the Intrinsics are there?
  55. 16. How do I pass a float value to XtSetValues?
  56. 17. How do I write a resource converter?
  57. 18. How do I open multiple displays?
  58. 19. What changed from R3 to R4 to R5?
  59. 20. Where are the resources loaded from?
  60. 21. What order are callbacks executed in?
  61. 22. How do I know if a widget is visible?
  62. 23. How do I reparent a widget in Xt, i.e. XtReparentWidget()?
  63. 24. Why use XtMalloc, XtFree, etc?
  64. 25. How to debug an Xt application?
  65. 26. Why don't XtAddInput(), XtAddTimeout() and XtAddWorkProc() work?
  66. 27. What is and how can I implement drag and drop?
  67. 28. How can I add a C++ member function as a widget callback?
  68. 29. How can I identify the children of a manager widget?
  69. 30. Can I use XtMoveWidget(), ... to move widgets I created?
  70. 31. Why is XtGetValues() on XtNx, XtNy of my top level shell wrong?
  71. 32. Why do some people use XmN<something> as resource names?
  72. 33. How do I make my life easier when designing an application?
  73. 34. Why can't I override translations? Only the first item works.
  74. 35. Why do I get "Warning: Widget class version mismatch"?
  75. 36. Where can I get a good file-selector widget?
  76. 37. Where can I find a hypertext widget or source code?
  77. 38. What widget is appropriate to use as a drawing canvas?
  78. 39. What is this link problem with _get_wmShellWidgetClass?
  79. 40. Why does XtGetValues not work for me (sic)?
  80. 41. Is this a memory leak in the X11R4 XtDestroyWidget()?!
  81. 42. Is this a memory leak in the X11R4 deletion of work procs?!
  82. 43. How do I query the user synchronously using Xt?
  83. 44. How do I simulate a button press/release event for a widget?
  84. 45. How to use Fallback resources (can I specify colors)?
  85. 46. What is the preferred way of setting the application resources?
  86.  
  87. ----------------------------------------------------------------------
  88. Subject: 0.  Xt Glossary
  89. ----------------------------------------------------------------------
  90.  
  91. o The Xt Intrinsics implement an object oriented interface to C code
  92.   to allow useful graphical components to be created.  Included with
  93.   this are classes that provide the base functionality: Object,
  94.   RectObj, Core, Composite, Constraint, Shell, OverrideShell, WMShell,
  95.   etc.  The terms "Xt" and "Intrinsics" are used interchangeably,
  96.   however, they are used very precisely to mean a specific library of the X
  97.   window system.  In particular, it does not include the Athena,
  98.   Motif, OLIT or any other widget set.  Without further widgets the
  99.   Intrinsics are not especially useful.
  100.  
  101. o A widget refers to a user interface abstraction created via Xt.  The
  102.   precise use, is any object that is a subclass of the Core class.  It
  103.   is used loosely to refer to anything that is a subclass of the
  104.   Object class although these are more accurately called windowless
  105.   widgets or gadgets.
  106.  
  107. o Xlib is the C interface to the X11 protocol.  It is one layer below
  108.   the Xt Intrinsics.  Typically a widget uses relatively few Xlib
  109.   functions because Xt provides most such services although an
  110.   understanding of Xlib helps with problems.
  111.  
  112. ----------------------------------------------------------------------
  113. Subject: 1.  Software Versions
  114. ----------------------------------------------------------------------
  115.  
  116. The following are the latest versions of Xt based software:
  117.         _____________________________________________________________
  118.     Software    Version        Released    Next Expected
  119.         _____________________________________________________________
  120.     X11R4        patch 18            (none)
  121.     X11R5        patch 26    11/3/93        ??
  122.     Athena Widgets    (see X11R5)
  123.     Motif        1.2.3        9/16/93        ??
  124.     OLIT        ??        ??        ??
  125.     Xtra        2.5        6/15/92        ??
  126.     Xw        X11R4                (none)
  127.     Xcu        X11R5                (none)
  128.     fwf        3.4        1/11/92        4/93
  129.         _____________________________________________________________
  130.  
  131. ----------------------------------------------------------------------
  132. Subject: 2.  Related FAQ's
  133. ----------------------------------------------------------------------
  134. David B. Lewis (uunet!craft!faq) maintains the FAQ on X.  It
  135. is posted monthly on comp.windows.x and located on ftp.x.org in contrib/FAQ.
  136.  
  137. Liam R. E. Quin (lee@sq.sq.com) posts an FAQ list on Open Look to 
  138. comp.windows.x.  
  139.  
  140. Brian Dealy (dealy@kong.gsfc.nasa.gov) posts an FAQ list on Motif to
  141. comp.windows.x.motif. it is also on ftp.x.org under contrib/Motif-FAQ
  142.  
  143. Peter Ware (ware@cis.ohio-state.edu) posts an FAQ list for
  144. comp.windows.x.intrinsics; it is on ftp.x.org in contrib/FAQ-Xt.
  145.  
  146. ----------------------------------------------------------------------
  147. Subject: 3.  Why does my app core dump when I use signals/alarms/cthreads?
  148. ----------------------------------------------------------------------
  149.  
  150. In brief, Xlib, Xt and most widget sets have no mutual exclusion for
  151. critical sections.  Any interrupt handler is likely to leave one of
  152. the above libraries in an inconsistent state -- such as all the
  153. appropriate flags not yet set, dangling pointers, in the middle of a
  154. list traversal, etc.  Note that the ANSI C standard points out that
  155. behavior of a signal handler is undefined if the signal handler calls
  156. any function other than signal() itself, so this is not a problem
  157. specific to Xlib and Xt; the POSIX specification mentions other
  158. functions which may be called safely but it may not be assumed that
  159. these functions are called by Xlib or Xt functions.
  160.  
  161. The only safe way to deal with signals is to set a flag in the
  162. interrupt handler.  This flag later needs to be checked either by a
  163. work procedure or a timeout callback.  It is incorrect to add either
  164. of these in the interrupt handler.  As another note, it is dangerous
  165. to add a work procedure that never finishes.  This effectively
  166. preempts any work procedures previously added and so they will never
  167. be called.  Another option is to open a pipe, tell the event loop
  168. about the read end using XtAppAddInput() and then the signal handler
  169. can write a byte to the write end of the pipe for each signal.
  170. However, this could deadlock your process if the pipe fills up.
  171.  
  172. Why don't the Intrinsics deal with this problem?  Primarily because it
  173. is supposed to be a portable layer to any hardware and operating
  174. system.   Is that a good enough reason -- I don't think so.
  175.  
  176.         Note: the article in The X Journal 1:4 and the example in O'Reilly
  177. Volume 6 are in error.
  178.  
  179. ----------------------------------------------------------------------
  180. Subject: 4.  How do I use a different visual than the default?
  181. ----------------------------------------------------------------------
  182.  
  183. This requires a more complicated answer than it should.  A window has
  184. three things that are visual specific -- the visual, colormap and
  185. border pixmap.  All widgets have their own Colormap and BorderPixmap
  186. resource; only shell widgets have Visual resources (another questions
  187. deals with why shells have a Visual).  The default value of these
  188. resources is CopyFromParent which does exactly what it says.  In the
  189. shell widget CopyFromParent gets evalulated as DefaultVisualOfScreen
  190. and DefaultColormapOfScreen.  When any one of the three resources is
  191. not properly set, a BadMatch error occurs when the window is
  192. created.  They are not properly set because each of the values depends
  193. on the visual being used.  
  194.  
  195. How to get this to work?  There are two parts to the answer.  The
  196. first is if you want an application to start with a particular visual
  197. and the second is if you want a particular shell within an application
  198. to start with a different visual.  The second is actually easier
  199. because the basic information you need is available.  The first is a
  200. little harder because you'll need to initialize much of the toolkit
  201. yourself in order to determine the needed information.
  202.  
  203. /*
  204.  * Some sample code to start up an application using something other
  205.  * than the default visual.
  206.  *
  207.  * To compile:
  208.  *    cc -g visual.c -o visual -lXaw -lXmu -lXt -lXext -lX11 -lm
  209.  *
  210.  * To run:
  211.  *    ./visual -geometry 300x300 -depth 24 -visual StaticColor -fg blue -bg yellow
  212.  *
  213.  * you need to move the mouse to get the particular visuals colormap
  214.  * to install.
  215.  */
  216.  
  217. #include <X11/Intrinsic.h>
  218. #include <X11/StringDefs.h>
  219. #include <X11/Shell.h>
  220.  
  221. typedef struct
  222. {
  223.     Visual    *visual;
  224.     int    depth;
  225. } OptionsRec;
  226.  
  227. OptionsRec    Options;
  228.  
  229. XtResource resources[] =
  230. {
  231.     {"visual", "Visual", XtRVisual, sizeof (Visual *),
  232.     XtOffsetOf (OptionsRec, visual), XtRImmediate, NULL},
  233.     {"depth", "Depth", XtRInt, sizeof (int),
  234.     XtOffsetOf (OptionsRec, depth), XtRImmediate, NULL},
  235. };
  236.  
  237. XrmOptionDescRec Desc[] =
  238. {
  239.     {"-visual", "*visual", XrmoptionSepArg, NULL},
  240.     {"-depth", "*depth", XrmoptionSepArg, NULL}
  241. };
  242.  
  243.  
  244.  
  245. int
  246. main (argc, argv)
  247.     int        argc;
  248.     char        **argv;
  249. {
  250.     XtAppContext    app;        /* the application context */
  251.     Widget        top;        /* toplevel widget */
  252.     Display        *dpy;        /* display */
  253.     char        **xargv;    /* saved argument vector */
  254.     int        xargc;        /* saved argument count */
  255.     Colormap    colormap;    /* created colormap */
  256.     XVisualInfo    vinfo;        /* template for find visual */
  257.     XVisualInfo    *vinfo_list;    /* returned list of visuals */
  258.     int        count;        /* number of matchs (only 1?) */
  259.     Arg        args[10];
  260.     Cardinal    cnt;
  261.     char        *name = "test";
  262.     char        *class = "Test";
  263.  
  264.     /*
  265.      * save the command line arguments
  266.      */
  267.  
  268.     xargc = argc;
  269.     xargv = (char **) XtMalloc (argc * sizeof (char *));
  270.     bcopy ((char *) argv, (char *) xargv, argc * sizeof (char *));
  271.  
  272.     /*
  273.      * The following creates a _dummy_ toplevel widget so we can
  274.      * retrieve the appropriate visual resource.
  275.      */
  276.     cnt = 0;
  277.     top = XtAppInitialize (&app, class, Desc, XtNumber (Desc), &argc, argv,
  278.                    (String *) NULL, args, cnt);
  279.     dpy = XtDisplay (top);
  280.     cnt = 0;
  281.     XtGetApplicationResources (top, &Options, resources,
  282.                    XtNumber (resources),
  283.                    args, cnt);
  284.     cnt = 0;
  285.     if (Options.visual && Options.visual != DefaultVisualOfScreen (XtScreen (top)))
  286.     {
  287.         XtSetArg (args[cnt], XtNvisual, Options.visual); ++cnt;
  288.         /*
  289.          * Now we create an appropriate colormap.  We could
  290.          * use a default colormap based on the class of the
  291.          * visual; we could examine some property on the
  292.          * rootwindow to find the right colormap; we could
  293.          * do all sorts of things...
  294.          */
  295.         colormap = XCreateColormap (dpy,
  296.                         RootWindowOfScreen (XtScreen (top)),
  297.                         Options.visual,
  298.                         AllocNone);
  299.         XtSetArg (args[cnt], XtNcolormap, colormap); ++cnt;
  300.  
  301.         /*
  302.          * Now find some information about the visual.
  303.          */
  304.         vinfo.visualid = XVisualIDFromVisual (Options.visual);
  305.         vinfo_list = XGetVisualInfo (dpy, VisualIDMask, &vinfo, &count);
  306.         if (vinfo_list && count > 0)
  307.         {
  308.             XtSetArg (args[cnt], XtNdepth, vinfo_list[0].depth);
  309.             ++cnt;
  310.             XFree ((XPointer) vinfo_list);
  311.         }
  312.     }
  313.     XtDestroyWidget (top);
  314.  
  315.  
  316.     /*
  317.      * Now create the real toplevel widget.
  318.      */
  319.     XtSetArg (args[cnt], XtNargv, xargv); ++cnt;
  320.     XtSetArg (args[cnt], XtNargc, xargc); ++cnt;
  321.     top = XtAppCreateShell ((char *) NULL, class,
  322.                 applicationShellWidgetClass,
  323.                 dpy, args, cnt);
  324.  
  325.     /*
  326.      * Display the application and loop handling all events.
  327.      */
  328.     XtRealizeWidget (top);
  329.     XtAppMainLoop (app);
  330.     return (0);
  331. }
  332.  
  333. ----------------------------------------------------------------------
  334. Subject: 5.  Which visual should an application use?
  335. ----------------------------------------------------------------------
  336.  
  337. This is a point that can be argued about but one opinion is there is
  338. no way for an application to know the appropriate visual -- it has to
  339. be specified by the user.  If you disagree with this then your
  340. application probably falls into the category of always using the
  341. default visual or it is hardware specific and expects some particular
  342. visual such as 24bit TrueColor with an OverlayPlane extension (or some
  343. such).
  344.  
  345. Why?  No application runs in isolation.  Depending on the way a server
  346. allocates resources I may not always want your application to run in
  347. TrueColor mode if it is going to mess up my other applications.  I may
  348. be very upset if it chooses to run in GreyScale instead of PsuedoColor
  349. or just monochrome.
  350.  
  351. As an example, on a low end color Sun server there are many different
  352. possible visuals: monochrome, 256 entry colormap, static gray, static
  353. color, and a 3/3/2 TrueColor.  The SGI Iris's offer all the above 
  354. plus 12 bit TrueColor, 24 bit TrueColor, an Overlay Plane.
  355.  
  356. ----------------------------------------------------------------------
  357. Subject: 6.  Why do only Shell widgets have a Visual?
  358. ----------------------------------------------------------------------
  359.  
  360. This is strictly by convention.  It makes it possible for an arbitrary
  361. widget to know that the visual it uses can be found by looking for the
  362. shell widget that is its ancestor and obtaining the visual of that
  363. shell.
  364.  
  365. A widget can have its own visual resource.  If it does, it must have
  366. its own realize method to use the visual when it calls
  367. XCreateWindow().  You should also make this a resource that can be
  368. obtained with XtGetValues() so other widgets can find it.  A
  369. reasonable value is probably XtNvisual.
  370.  
  371. ----------------------------------------------------------------------
  372. Subject: 7.  Which visual, depth and colormap do Shells inherit?
  373. ----------------------------------------------------------------------
  374.  
  375. The default value for these resources are set to CopyFromParent.  This
  376. is interpreted as the DefaultColormapOfScreen(), DefaultDepthOfScreen()
  377. and the default visual of the screen if the widget has no parent -- i.e.
  378. it is an applicationShellWidgetClass and the root of your widget tree.
  379.  
  380. If the parent of the widget is not null, then the shell copies
  381. colormap and depth from its parent and uses CopyFromParent as the
  382. visual.
  383.  
  384. ----------------------------------------------------------------------
  385. Subject: 8.  I've done all the above and I still get a BadMatch error.  Why?
  386. ----------------------------------------------------------------------
  387.  
  388. Some resource converters improperly cache references.  This was
  389. especially true of X11R3 and earlier versions of Motif.
  390.  
  391. ----------------------------------------------------------------------
  392. Subject: 9.  Why doesn't my widget get destroyed when I call XtDestroyWidget()?
  393. ----------------------------------------------------------------------
  394.  
  395. See section 2.8 of the Xt specification.
  396.  
  397. It eventually does get destroyed, just not immediately.  The
  398. Intrinsics destroy a widget in a two-phase process.  First it and all
  399. of its children have a flag set that indicate it is being destroyed.
  400. It is then put on a list of widgets to be destroyed.  This way any
  401. pending X events or further references to that widget can be cleaned
  402. up before the memory is actually freed.  The second phase is then
  403. performed after all callbacks, event handlers, and actions have
  404. completed, before checking for the next X event.  At this point the
  405. list is traversed and each widget's memory is actually free()'d, among
  406. other things.
  407.  
  408. As some further caveats/trivia, the widgets may be destroyed if the
  409. Intrinsics determine that they have no further references to the
  410. widgets on the list.  If so, then the phase 2 destruction occurs
  411. immediately.  Also, if nested event loops are used, widgets placed on
  412. the destroy list before entering the inner event loop are not
  413. destroyed until returning to the outer event loop.
  414.  
  415. ----------------------------------------------------------------------
  416. Subject: 10. How do I exit but still execute the DestroyCallbacks?
  417. ----------------------------------------------------------------------
  418.  
  419. The problem is if a simple and entirely reasonable approach to exiting
  420. an application is used, such as calling exit() directly, then a widget
  421. may not have a chance to clean up any external state -- such as open
  422. sockets, temporary files, allocated X resources, etc.  (this code for
  423. simplicity reasons assumes only a single toplevel widget):
  424.  
  425.  
  426.     Widget
  427.     ToplevelGet (gw)
  428.         Widget        gw;        /* widget to find toplevel */
  429.     {
  430.         Widget        top;
  431.  
  432.         for (top = gw; XtParent (top); top = XtParent (top))
  433.             /* empty */;
  434.         return (top);
  435.     }
  436.  
  437.     void
  438.     ExitCallback (gw, closure, call_data)
  439.         Widget        gw;        /* widget */
  440.         XtPointer    closure;    /* data the app specified */
  441.         XtPointer    call_data;    /* widget specific data */
  442.     {
  443.         Widget        toplevel;
  444.  
  445.         toplevel = ToplevelGet (gw);
  446.         XtUnmapWidget (toplevel);    /* make it disappear quickly */
  447.         XtDestroyWidget (toplevel);
  448.         exit (0);
  449.     }
  450.  
  451. One can see that the above code exit's immediately after destroying
  452. the toplevel widget.  The trouble is the phase 2 destruction may never
  453. occur.  
  454.  
  455. This works for most widgets and most applications but will not work
  456. for those widgets that have any external state.  You might think that
  457. since it works now it will always work but remember that part of the
  458. reason an object oriented approach is used is so one can be ignorant
  459. of the implementation details for each widget.  Which means that the
  460. widget may change and someday require that some external state is
  461. cleaned up by the Destroy callbacks.
  462.  
  463. One alternative is to modify ExitCallback() to set a global flag and
  464. then test for that flag in a private event loop.
  465. Or try the following code:
  466.  
  467.     #include <X11/Intrinsic.h>
  468.  
  469.     extern Widget ToplevelGet (
  470.     #if NeedFunctionPrototypes
  471.         Widget        gw
  472.     #endif
  473.     );
  474.  
  475.     extern Boolean ExitWorkProc (
  476.     #if NeedFunctionPrototypes
  477.         XtPointer    closure
  478.     #endif
  479.     );
  480.  
  481.     extern void ExitCallback (
  482.     #if NeedFunctionPrototypes
  483.         Widget        gw,
  484.         XtPointer    closure,
  485.         XtPointer    call_data
  486.     #endif
  487.     );
  488.  
  489.     Widget
  490.     ToplevelGet (gw)
  491.     Widget        gw;        /* widget to find toplevel */
  492.     {
  493.         Widget        top;
  494.  
  495.         for (top = gw; XtParent (top); top = XtParent (top))
  496.             /* empty */;
  497.         return (top);
  498.     }
  499.  
  500.  
  501.     void
  502.     ExitCallback (gw, closure, call_data)
  503.     Widget        gw;        /* widget */
  504.     XtPointer    closure;    /* data the app specified */
  505.     XtPointer    call_data;    /* widget specific data */
  506.     {
  507.         Widget        toplevel;
  508.  
  509.         toplevel = ToplevelGet (gw);
  510.         XtUnmapWidget (toplevel);    /* make it disappear quickly */
  511.         XtDestroyWidget (toplevel);
  512.         XtAppAddWorkProc (XtWidgetToApplicationContext (gw),
  513.                   ExitWorkProc, (XtPointer) NULL);
  514.     }
  515.  
  516.     Boolean
  517.     ExitWorkProc (closure)
  518.         XtPointer    closure;
  519.     {
  520.         exit (0);
  521.         /*NOTREACHED*/
  522.     }
  523.  
  524.  
  525. ExitCallback() adds a work procedure that will get called when the
  526. application is next idle -- which happens after all the events are
  527. processed and the destroy callbacks are executed.
  528.  
  529. ----------------------------------------------------------------------
  530. Subject: 11. How do I resize a Shell widget?
  531. ----------------------------------------------------------------------
  532.  
  533. After it is realized, one doesn't resize a Shell widget.  The proper
  534. thing is to resize the currently managed child of the Shell widget
  535. using XtSetValues().  The geometry change is then propagated to the
  536. Shell which asks the window manager which may or may not allow the
  537. request.  However, the Shell must have the resource
  538. XtNallowShellResize set to True otherwise it will not even ask the
  539. window manager to grant the request and the Shell will not resize.
  540.  
  541. To change the position of a Shell, use XtSetValues() on the Shell, not
  542. the child, and within the limits of the window manager it should be granted.
  543.  
  544. ----------------------------------------------------------------------
  545. Subject: 12. Why can't XtAppAddInput() handle files?
  546. ----------------------------------------------------------------------
  547.  
  548. It does, however Unix semantics for when I/O is ready for a file does
  549. not fit most peoples' intuitive model.  In Unix terms a file
  550. descriptor is ready for reading whenever the read() call would not
  551. block, ignoring the setting of optional flags that indicate not to
  552. block.  This works as expected for terminals, sockets and pipes.  For
  553. a file the read() will always return but the return indicates an EOF
  554. -- i.e. no more data.  The result is the code in the Intrinsics always
  555. calls the input handler because it always thinks something is about to
  556. be read.  The culprit is the select() system call or on SYSV based
  557. OS's it is the poll() system call.
  558.  
  559. How to get around this on a Unix system?  The best approach is to use
  560. another process to check for available input on the file.  Use a pipe
  561. to connect the application with this other process and pass the file
  562. descriptor from the pipe to XtAppAddInput().  A suitable program on
  563. BSD systems is "tail -f filename".
  564.  
  565. It's rumored that select() on some systems is not _completely_
  566. reliable.  In particular:
  567.  
  568.     - IBM AIX 3.1: this is one where it would work for a while
  569.       (several thousand times) and then stop until some other
  570.       event woke it up. This seemed to be the result of a race
  571.       condition in the Kernel.  IBM claims to have a fix for this.
  572.  
  573.     - Pyramid, doesn't work at all.
  574.  
  575.     - Ultrix (and possibly others where pipes are implemented as
  576.       sockets), wasn't completely broken, but although the writing
  577.       side wrote in 512 byte blocks the reading side received it
  578.       all broken up as if it was being put into the pipe a byte at
  579.       a time.  You can waste a lot of time by reading small blocks
  580.       (get raound it by detecting the situation and having
  581.       select() ignore the pipe for 10 mseconds - by then it had
  582.       been given the whole block).
  583.  
  584.  
  585. Note that all the above descriptions used Unix terminology such as
  586. read(), file descriptor, pipes, etc.  This is an OS dependent area and
  587. may not be identical on all systems.  However the Intrinsic designers
  588. felt it was a common enough operation that it should be included with
  589. part of the toolkit.  Why they didn't also deal with signals at this
  590. point I don't know.
  591.  
  592. ----------------------------------------------------------------------
  593. Subject: 13. What good books and magazines are there on Xt?
  594. ----------------------------------------------------------------------
  595.  
  596. I have a favorite that is the definitive reference.  To my perspective
  597. it offers a reasonable introduction but also goes into the full
  598. details of the Intrinsics.  When I started using it I was already
  599. familiar with Xt and the concepts behind it, so newcomers may or may
  600. not find it useful.  I've always found it accurate and complete, which
  601. means its a 1000 pages.
  602.  
  603. Asente, Paul J., and Swick, Ralph R., "X Window System Toolkit, The
  604.     Complete Programmer's Guide and Specification", Digital Press,
  605.     1990, ISBN 1-55558-051-3, order number EY-E757E-DP; and by
  606.     Prentice-Hall, ISBN 0-13-972191-6. Also available through DEC
  607.     Direct at 1-800-DIGITAL.
  608.  
  609. The other book I commonly recomend to novices is:
  610.  
  611. Young, Doug. "The X Window System: Applications and Programming with
  612.     Xt (Motif Version)," Prentice Hall, 1989 (ISBN 0-13-497074-8).
  613.     (ISBN 0-13-972167-3)
  614.  
  615. And of course O'Reilly has an entire series of manuals on X and Xt.
  616. O'Reilly ordering is 800-998-9938.  In particular, Volume 5 is an Xt
  617. reference done in manual page style.  The 3rd edition is extensively
  618. overhauled and goes far beyond the MIT manual pages.  I'm finding it
  619. very useful.  In particular, the permutted index and references to
  620. other manual pages help a great deal in chasing down related
  621. information.
  622.  
  623. I read two periodicals, "The X Resource" and the "The X Journal".
  624. These are the only two dealing specifically with X.  "The X Resource"
  625. is published quarterly, by O'Reilly, with one of the issues being the
  626. MIT X Consortium Technical Conference Proceedings.  There is no
  627. advertising.  I've found it informative with pretty good depth.  For
  628. orders, call 1-800-998-9938, or email cathyr@ora.com.  For editorial
  629. matters, email adrian@ora.com.  Table of contents are posted at
  630. math.utah.edu in ~ftp/pub/tex/bib in TeX form and on ftp.uu.net in
  631. ~ftp/published/oreilly/xresource in ASCII form.
  632.  
  633.  
  634. "The X Journal" is a bimonthly trade rag with lots of advertising.
  635. The articles are informative and oriented toward a less technical
  636. audience.  I read it more to see what's going on then with an
  637. expectation of learning a great deal (but remember, I represent a
  638. fairly small percentage of people).  Also, they have a pretty good
  639. collection of people on the advisory board and as columnists.  Call
  640. (908) 563-9033.
  641.  
  642. ----------------------------------------------------------------------
  643. Subject: 14. What Widgets are available?
  644. ----------------------------------------------------------------------
  645.  
  646. There are three popular widget sets:
  647.  
  648. Athena    - The set provided with X11.  This is sufficient for most
  649.       purposes but is on the ugly side.  Recently, a 3d look is
  650.       available for ftp on ftp.x.org:/contrib/Xaw3d.tar.Z.
  651. Motif    - From OSF available for a license fee and commonly shipped on
  652.       many workstation vendors platforms (almost everyone but
  653.       Sun).  It looks good and works well but personally I think
  654.       it is poorly implemented.
  655. OLIT    - The Open Look Intrinsics Toolkit is a set of widgets
  656.       implementing Sun's Open Look specification.  Developed by
  657.       AT&T.  I've never used it so can't comment on its quality.
  658.       I've heard rumours that it is a pain to actually get.
  659.  
  660. In addition the following collection of widgets are also available:
  661.  
  662. Xtra    - a library of widgets for sale from Graphical Software
  663.       Technology (310-328-9338).  It includes bar graph, stacked
  664.       bar graph, line graph, pie chart, xy plot, hypertext, help,
  665.       spreadsheet, and data entry form widgets.  I've never seen
  666.       them so I can't comment.
  667. FWF    - The Free Widget Foundation is attempting to collect a set of
  668.       freely available widgets.  Included are a Pixmap editor,
  669.       FileDialog, and a few others.  The current set of widgets
  670.       can be obtained via anonymous ftp from the machine
  671.       a.cs.uiuc.edu (128.174.252.1) in the file pub/fwf.shar.Z.
  672. Xcu    - The Cornell University widgets from Gene Dykes.  One of the
  673.       early widget sets released.  Provides a nice appearance for
  674.       buttons and has a mini command language.  Probably not so
  675.       widely used.
  676. Xs    - The Sony widget set.  This was around during R3 days but
  677.       seemed to disappear.  It looked like it had promise.
  678. Xw    - The HP widgets.  The precursor to Motif.  Originally written
  679.       for R3 there exists diffs to get it to work under R4 & R5.
  680.       Again, a pretty good widget set but has more or less died.
  681.       The precursor to this was the Xray toolkit which was
  682.       originally implemented for X10R4 and apparently provided
  683.       much experience for the designers of Xt.
  684. Xo    - A widget set I'm working on.  It's still primitive but you
  685.       can give it a try in archive.cis.ohio-state.edu:pub/Xo/*
  686.  
  687. The following specialized widgets are also available:
  688.  
  689. Tbl    - Implements a tabular layout of widgets.  Supports Motif
  690.       widgets as children.  Part of Wcl.
  691. Plots    - The Athena Plotting widgets (not the Athena widgets).
  692.       Contact gnb@bby.oz.au or joe@Athena.MIT.EDU.
  693.  
  694. ----------------------------------------------------------------------
  695. Subject: 15. What alternatives to the Intrinsics are there?
  696. ----------------------------------------------------------------------
  697.  
  698.     __________________________________________
  699.     Name        Language    Vendor
  700.     __________________________________________
  701.     Xview        C        Sun
  702.     OI        C++        ParcPlace
  703.     Interviews    C++        Stanford
  704.     Tcl/tk        C        sprite.berkeley.edu
  705.     __________________________________________
  706.  
  707.  
  708. However much I like C and admire the skill in both designing and
  709. implementing the Intrinsics, hopefully some alternative will develop
  710. in the next 3-5 years that uses an object oriented language.  Keep
  711. your eyes open and expect some change about the same time a language
  712. other than C _starts_ gaining acceptance.
  713.  
  714. ----------------------------------------------------------------------
  715. Subject: 16. How do I pass a float value to XtSetValues?
  716. ----------------------------------------------------------------------
  717.  
  718. First, what is going wrong is the structure for an Arg is (essentially)
  719.     typdef struct
  720.     {    
  721.         String    name;
  722.         long    value;
  723.     } Arg;
  724.  
  725. and the code:
  726.     Arg    arg;
  727.  
  728.     XtSetArg (arg, "name", 3.2)
  729.  
  730. expands to
  731.     Arg    arg;
  732.  
  733.     arg.name = "name";
  734.     arg.value = 3.2;
  735.  
  736. you can see that with normal C type conversions, the arg.value
  737. gets the integer "3" instead of the floating point value "3.2".  When
  738. the value is copied into the widget resource, the bit pattern is
  739. wildly different than that required for a floating point value.  So,
  740. how to get around this?
  741.  
  742. The following macro is from the Athena widgets document and I am now
  743. recomending it over the previous suggestions.
  744.  
  745. #define XtSetFloatArg(arg, n, d) \
  746.     if (sizeof(float) > sizeof(XtArgVal)) { \
  747.         XtSetArg(arg, n, &(d)); \
  748.     } else { \
  749.         XtArgVal *ld = (XtArgVal *)&(d); \
  750.         XtSetArg(arg, n, *ld); \
  751.     }
  752.  
  753.  
  754. ----------------------------------------------------------------------
  755. Subject: 17. How do I write a resource converter?
  756. ----------------------------------------------------------------------
  757.  
  758. Courtesy of Rich Thomson (rthomson@dsd.es.com):
  759.  
  760. The following discussion of resource converters assumes R4 (or R5)
  761. Intrinsics.  Resource converters changed between R3 and R4 to allow
  762. for destructors and caching of converted values.
  763.  
  764. There are several main types of resource converters:
  765.  
  766.     string to data type
  767.     data type to string
  768.     data type to data type
  769.  
  770. i) string to data type
  771.     Usually a string to data type converter has a fixed set of strings
  772.     that will be converted to data type values.  This is most often
  773.     used to map enumerated names to enumerated values:
  774.  
  775.     Name        Value
  776.     "True"        1
  777.     "False"        0
  778.  
  779.     In this case, the string to data type converter needs to compare
  780.     the resource value to the list of fixed strings.  This is most
  781.     readily accomplished by the use of the "quark" mechanism of the
  782.     resource manager.  The resource value is turned into a quark,
  783.     which is a unique representation of the string that fits into a
  784.     single word.  Then the resource quark is compared against the
  785.     quarks for the fixed strings representing the enumerated values.
  786.  
  787.     If there are many enumerated strings in the converter (or many
  788.     converters, each with a small number of enumeration strings), then
  789.     a global initialization routine might be used to turn all the
  790.     resource strings into quarks.  That way, the first time one of
  791.     these converters is used, the strings will be turned into quarks
  792.     and held in static variables for use in the next invocation of one
  793.     of the converters.
  794.  
  795. ii) data type to string
  796.     This type of converter is slightly easier than the string to data
  797.     type converters since the use of quarks isn't necessary.  Instead,
  798.     the data type value is simply converted to a string value,
  799.     probably by the use of sprintf.
  800.  
  801.     Data type to string converters are useful for applications that
  802.     wish to convert an internal data type value into a string so that
  803.     they can write out a valid resource specification to a file.  This
  804.     mechanism can be used to provide a "snapshot" of application state
  805.     into a file.  This snapshot can be used to restore the program to
  806.     a known state via the usual X resource database mechanisms.
  807.  
  808.     If you are taking the trouble to write a string to data type
  809.     converter, it isn't much extra effort to write the data type to
  810.     string converter.  Writing both at the same time helps to ensure
  811.     that they are consistent.
  812.  
  813. iii) data type to data type
  814.     This type of converter is used to convert an existing data type
  815.     value to another data type.  For instance, an X pixel value can be
  816.     converted to an RGB data type that contains separate fields for
  817.     red, green and blue.
  818.  
  819.  
  820. The type signature for a resource converter is as follows:
  821.  
  822. typedef Boolean (*XtTypeConverter)(Display *, XrmValuePtr, Cardinal *,
  823.     XrmValuePtr, XrmValuePtr, XtPointer *);
  824.     Display *dpy;
  825.     XrmValuePtr args;
  826.     Cardinal *num_args;
  827.     XrmValuePtr fromVal;
  828.     XrmValuePtr toVal;
  829.     XtPointer *converter_data;
  830.  
  831. When the converter is invoked, the "fromVal" argument points to the source
  832. X resource manager value and the "toVal" argument points to the
  833. destination X resource manager value.  The "converter_data" argument
  834. is an opaque pointer to some converter-specific data that is specified
  835. when the converter is registered.  The "args" and "num_args" arguments
  836. allow extra information to be passed to the converter when it is
  837. invoked.  For instance, the Pixel to RGB structure converter discussed
  838. above would need colormap and visual arguments in which to lookup the
  839. Pixel to obtain the RGB values corresponding to that pixel.
  840.  
  841. Care must be taken with the "toVal" argument.  An XrmValue has the
  842. following type definition and specifies a size and location for a
  843. converted value:
  844.  
  845. typedef struct {
  846.     unsigned int    size;
  847.     caddr_t         addr;
  848. } XrmValue, *XrmValuePtr;
  849.  
  850. When the converter is invoked, the address may point to a location of
  851. the given size for the converted value or the location can be NULL.
  852. In the former case, the converter should ensure that the size of the
  853. destination area is large enough to handle the converted value.  If
  854. the destination area is not large enough, then the converter should
  855. set the size to the amount of space needed and return False.  The
  856. caller can then ensure that enough space is allocated and reinvoke the
  857. converter.  If the size is large enough, then the converter can simply
  858. copy the converted value into the space given and return True.
  859.  
  860. If the location is NULL, then the converter can assign the location to
  861. the address of a static variable containing the converted value and
  862. return True.
  863.  
  864. When writing a group of converters, this code is often repeated and it
  865. becomes convenient to define a macro:
  866.  
  867.     #define DONE(var, type) \
  868.       if (toVal->addr) \
  869.     { \
  870.       if (toVal->size < sizeof(type)) \
  871.         { \
  872.           toVal->size = sizeof(type); \
  873.           return False; \
  874.         } \
  875.       else \
  876.         *((type *) toVal->addr) = var; \
  877.     } \
  878.       else \
  879.     toVal->addr = (caddr_t) &var; \
  880.       toVal->size = sizeof(type); \
  881.       return True;
  882.  
  883.     #define DONESTR(str) \
  884.       if (toVal->addr && toVal->size < sizeof(String)) \
  885.     { \
  886.       toVal->size = sizeof(String); \
  887.       return False; \
  888.     } \
  889.       else \
  890.     toVal->addr = (caddr_t) str; \
  891.       toVal->size = sizeof(String); \
  892.       return True;
  893.  
  894. Inside the converter, it is a good idea to perform a little safety
  895. checking on the "num_args" and "args" arguments to ensure that your
  896. converter is being called properly.
  897.  
  898. Once you have written your converter, you need to register it with the
  899. Intrinsics.  The Intrinsics invokes resource converters when creating
  900. widgets and fetching their resource values from the resource database.
  901.  
  902. To register a converter with a single application context, use
  903. XtAppSetTypeConverter:
  904.  
  905. void XtAppSetTypeConverter(context, from, to, converter, args, num_args,
  906.     cache, destructor)
  907.     XtAppContext context;
  908.     String from;
  909.     String to;
  910.     XtTypeConverter converter;
  911.     XtConvertArgList args;
  912.     Cardinal num_args;
  913.     XtCacheType cache;
  914.     XtDestructor destructor;
  915.  
  916. To register a converter with all application contexts, use
  917. XtSetTypeConverter:
  918.  
  919. void XtSetTypeConverter(from, to, converter, args, num_args,
  920.     cache, destructor)
  921.     String from;
  922.     String to;
  923.     XtTypeConverter converter;
  924.     XtConvertArgList args;
  925.     Cardinal num_args;
  926.     XtCacheType cache;
  927.     XtDestructor destructor;
  928.  
  929. In the R3 Intrinsics, there were the routines XtAppAddConverter and
  930. XtAddConverter; these have been superseded by XtAppSetTypeConverter
  931. and XtSetTypeConverter.  Whenever possible, the newer routines should be
  932. used.
  933.  
  934. When a converter is registered with the Intrinsics, a "cache" argument
  935. specifies how converted resource values are to be cached:
  936.  
  937.     XtCacheNone        Don't cache any converted values
  938.     XtCacheAll        Cache all converted values
  939.     XtCacheByDisplay    Cache converted values on a per display basis
  940.  
  941. Caching converted values that require a round-trip to the server is a
  942. good idea (for instance string to Pixel conversions).
  943.  
  944. The "destructor" argument is a routine that is invoked then the
  945. resource is destroyed, either because its cached reference count has
  946. been decremented to zero or because the widget owning the value is
  947. being destroyed.  XtDestructor has the following type definition:
  948.  
  949. typedef void (*XtDestructor)(XtAppContext, XrmValuePtr, XtPointer,
  950.     XrmValuePtr, Cardinal *);
  951.     XtAppContext context;
  952.     XrmValuePtr to;
  953.     XtPointer converter_data;
  954.     XrmValuePtr args;
  955.     Cardinal *num_args;
  956.  
  957. The destructor is invoked to free any auxiliary storage associated
  958. with the "to" argument, but does not actually free the storage pointed
  959. to by the "to" argument itself (to->addr).  The destructor is passed
  960. the extra arguments that were passed to the converter when the
  961. conversion was performed (for instance, colormap and visual arguments
  962. for the string to Pixel converter since the destructor would need to
  963. free the allocated Pixel from the colormap) as well as the private
  964. data passed in when the converter was registered.
  965.  
  966. Sample converter code can be found in the following files in the MIT
  967. R5 distribution:
  968.  
  969.     mit/lib/Xt/Converters.c
  970.     contrib/lib/PEXt/Converters.c
  971.     contrib/lib/PEXt/Converters.h
  972.  
  973. ----------------------------------------------------------------------
  974. Subject: 18. How do I open multiple displays?
  975. ----------------------------------------------------------------------
  976.  
  977. See "Multi-user Application Software Using Xt", The X Resource, Issue 3,
  978. (Summer 1992) by Oliver Jones for a complete coverage of the issues
  979. involved.  Most of this answer is based on that article.  In a
  980. nutshell, one uses XtOpenDisplay() to add each display to a _single_
  981. application context and then XtCloseDisplay() to shutdown each display
  982. and remove it from the application context.
  983.  
  984. The real problems occur when trying to close down a display.  This can
  985. happen 3 ways:
  986.     1. User selects a "quit" button on one of the displays,
  987.     2. User has window manager send a WM_DELETE_WINDOW message,
  988.     3. Server disconnect -- possibly from a KillClient message,
  989.        server shutdown/crash, or network failure.
  990.  
  991. I'll assume you can deal gracefully with 1 & 2 since it is _merely_ a
  992. problem of translating a Widget to a display and removing that
  993. display.  If not, then read the Oliver Jones article.
  994.  
  995. The third one is difficult to handle.  The following is based on the
  996. Oliver Jones article and I include it here because it is a difficult
  997. problem.
  998.  
  999. The difficulty arises because the Xlib design presumed that an I/O
  1000. error is always unrecoverable and so fatal.  This is essentially true
  1001. for a single display X based application, but not true for a
  1002. multiple display program or an application that does things other than
  1003. display information on an X server.  When an X I/O error occurs the
  1004. I/O error handler is called and _if_ it returns then an exit()
  1005. happens.  The only way around this is to use setjmp/longjmp to avoid
  1006. returning to the I/O error handler.  The following code fragment
  1007. demonstrates this:
  1008.  
  1009. #include <setjmp.h>
  1010. jmp_buf XIOrecover;
  1011.  
  1012. void
  1013. XIOHandler (dpy)
  1014.     Display        *dpy;
  1015. {
  1016.     destroyDisplay (dpy);
  1017.     longjmp (XIOrecover, 1);
  1018. }
  1019.  
  1020. main ()
  1021. {
  1022.     ...
  1023.     if (setjmp (XIOrecover) == 0)
  1024.         XSetIOErrorHandler (XIOHandler);
  1025.     XtAppMainLoop (app_context);
  1026. }
  1027.  
  1028. The destroyDisplay() is something that given a Display pointer can go
  1029. back to the application specific data and perform any necessary
  1030. cleanup.  It should also call XtCloseDisplay().
  1031.  
  1032. For those of you unfamiliar with setjmp/longjmp, when setjmp() is
  1033. first called it returns a 0 and save's enough information in the
  1034. jmp_buf that a latter execution of longjmp() can return the program to
  1035. the same state as if the setjmp() was just executed.  The return value
  1036. of this second setjmp() is the value of the second argument to
  1037. longjmp().  There are several caveats about using these but for this
  1038. purpose it is adequate.
  1039.  
  1040. Some other problems you might run into are resource converters that
  1041. improperly cache resources.  The most likely symptoms are Xlib errors
  1042. such as BadColor, BadAtom, or BadFont.  There may be problems with the
  1043. total number of displays you can open since typically only a limited
  1044. number of file descriptors are available with 32 being a typical
  1045. value.  You may also run into authorization problems when trying to
  1046. connect to a display.
  1047.  
  1048. There was much discussion in comp.windows.x about this topic in
  1049. November of 91.  Robert Scheifler posted an article which basically
  1050. said this is the way it will be and Xlib will not change.
  1051.  
  1052. ----------------------------------------------------------------------
  1053. Subject: 19. What changed from R3 to R4 to R5?
  1054. ----------------------------------------------------------------------
  1055.  
  1056. This addresses only changes in the Intrinsics.  First, the general
  1057. changes for each release are described.  Then a, certainly incomplete,
  1058. list of new functions added and others that are now deprecated are
  1059. listed.  Brevity is a primary goal.
  1060.  
  1061. Much of the following information is retrieved from Chapter 13 of the MIT
  1062. Xt Intrinsics Manual and from O'Reilly Volume 5, 3rd edition.
  1063.  
  1064. From R3 to R4
  1065. - Addition of gadgets (windowless widgets)
  1066. - New resource type converter interface to handle cacheing and
  1067.   additional  data.
  1068. - Variable argument list interface.
  1069. - #define XtSpecificationRelease 4  (added with this release)
  1070. - WMShellPart, TopLevelShellPart & TransientShellPart changed
  1071.   incompatibly.
  1072. - core.initialize, core.set_values added ArgList and count parameters
  1073. - event handlers had continue_to_dispatch parameter added
  1074. - core.set_values_almost specification changed.
  1075. - core.compress_exposure changed to an enumerated data type from Boolean
  1076. - core.class_inited changed to enumerated data type from Boolean
  1077. - constraint.get_values_hook added to extension record
  1078. - core.initialize_hook obsolete as info is passed to core.initialize
  1079. - shell.root_geometry_manager added to extension record
  1080. - core.set_values_hook obsolete as info is passed to core.set_values
  1081. - Calling XtQueryGeometry() must store complete geometry.
  1082. - Added UnrealizeCallback.
  1083. - XtTranslateCoords() actually works under R4.
  1084.  
  1085. From R4 to R5:
  1086. - Psuedo resource baseTranslation added.
  1087. - Searching for app-default, and other files, made more flexible
  1088. - customization resource added.
  1089. - Per-screen resource database.
  1090. - Support permanently allocated strings.
  1091. - Permanetly allocated strings required for several class fields.
  1092. - The args argument to XtAppInitialize, XtVaAppInitialize,
  1093.   XtOpenDisplay, XtDisplayInitialize, and XtInitialize were changed
  1094.   from Cardinal* to int*
  1095. - Many performance improvements (this is summarized from the article
  1096.   "Xt Performance Improvements in Release 5" by Gabe Beged-Dov in "The
  1097.   X Resource", Issue 3):
  1098.     - XrmStringToQuark() augmented with XrmPermStringToQuark() to
  1099.       avoid string copies.  Several fields in the class record are
  1100.       indicated as needing permanent strings.
  1101.     - Using an array of Strings for resources
  1102.     - Callback lists redesigned to use less memory
  1103.     - Translation manager redesigned and rewritten so it takes
  1104.       less memory, translation tables merges are faster, cache of
  1105.       action bindings
  1106.     - Keycode to Keysyms are cached.
  1107.     - Better sharing of GC's with modifiable fields
  1108.     - Window to Widget translation uses less space and faster
  1109.     - Does not malloc space for widget name since quark is available
  1110.     - Widget space is allocated to include the constraints
  1111.     - Over several example programs, about a 26% reduction in
  1112.       memory usage.
  1113.  
  1114. Functions new with R5:
  1115. ----------------------
  1116. XtAllocateGC()        - sharable GC with modifiable fields  
  1117. XtGetActionList()    - get the action table of a class
  1118. XtScreenDatabase()    - return resource database for a screen
  1119. XtSetLanguageProc()    - register language procedure called to set locale
  1120.  
  1121.  
  1122. Functions new with R4:
  1123. ----------------------
  1124. XtAppAddActionHook()    - procedure to call before _every_ action.
  1125. XtAppInitialize()    - lots of initialization work.
  1126. XtAppReleaseCacheRefs()    - decrement cache reference count for converter
  1127. XtAppSetFallbackResources() - specify default resources
  1128. XtAppSetTypeConverter()    - register a new style converter
  1129. XtCallCallbackList()    - directly execute a callback list
  1130. XtCallConverter    ()    - invoke a new style converter
  1131. XtCallbackReleaseCacheRef() - release a cached resource value
  1132. XtCallbackReleaseCacheRefList() - release a list of cached resource values
  1133. XtConvertAndStore()    - find and call a resource converter
  1134. XtDirectConvert()    - Invoke old-style converter
  1135. XtDisplayOfObject()    - Return the display
  1136. XtDisplayStringConversionWarning() - issue a warning about conversion
  1137. XtFindFile()        - Find a file
  1138. XtGetActionKeysym()    - Retrieve keysym & modifies for this action
  1139. XtGetApplicationNameAndClass() - return name and class
  1140. XtGetConstraintResourceList() - get constraints for a widget
  1141. XtGetKeysymTable()    - return keycode-to-keysym mapping table
  1142. XtGetMultiClickTime()    - read the multi-click time
  1143. XtGetSelectionRequest()    - retrieve the SelectionRequest event
  1144. XtGetSelectionValueIncremental() - obtain the selection value incrementally
  1145. XtGetSelectionValuesIncremental() - obtain the selection value incrementally
  1146. XtInitializeWidgetClass() - initialize a widget class manually
  1147. XtInsertEventHanlder()    - register event handler before/after others
  1148. XtInsertRawEventHandler() - register event handler without modify input mask
  1149. XtIsObject()        - test if subclass of Object
  1150. XtIsRectObj()        - test if subclass of RectObj
  1151. XtKeysymToKeyCodeList()    - return list of keycodes
  1152. XtLastTimestampProcessed() - retrieve most recent event time
  1153. XtMenuPopdown        - Action for popping down a widget
  1154. XtMenuPopup        - Action for popping up a widget
  1155. XtOffsetOf        - macro for structure offsets
  1156. XtOwnSelectionIncremental() - make selection data availabe incrementally
  1157. XtPoupSpringLoaded()    - map a spring-loaded popup
  1158. XtRegisterGrabAction()    - indicate action procedure needs a passive grab
  1159. XtRemoveActiohHook()    - remove function called after every action
  1160. XtResolvePathname()    - find a file
  1161. XtScreenOfObject()    - return screen of object.
  1162. XtSetMultiClickTime()    - set the multi-click time
  1163. XtSetWMColormapWindows() - set WM_COLORMAP_WINDOWS for custom colormaps
  1164. XtUngrabButton()    - cancel a passive button grab
  1165. XtUngrabKey()        - cancel a passive key grab
  1166. XtUngrabKeybard()    - release an active keyboard grab
  1167. XtUngrabPointer()    - release an active pointer grab
  1168. XtVa*()            - varags interfaces to a bunch of functions
  1169. XtWindowOfObject()    - return Window of nearest widget ancestor
  1170.  
  1171.  
  1172. Deprecated        Replacement            When
  1173. ----------------------------------------------------------------------
  1174. XtAddActions()        XtAppAddActions()        R3
  1175. XtAddConverter()    XtAppAddConverter()        R3
  1176. XtAddInput()        XtAppAddInput ()        R3
  1177. XtAddTimeout()        XtAppAddTimeout()        R3
  1178. XtAddWorkProc()        XtAppAddWorkProc()        R3
  1179. XtConvert()        XtConvertAndStore()        R4
  1180. XtCreateApplicationShell XtAppCreateShell()        R3
  1181. XtDestroyGC()        XtReleaseGC()            R3
  1182. XtError()        XtAppError()            R3
  1183. XtGetErrorDatabase()    XtAppGetErrorDatabase        R3
  1184. XtGetErrorDatabaseText() XtAppGetErrorDatabaseText    R3
  1185. XtGetSelectionTimeout()    XtAppGetSelectionTimeout    R3
  1186. XtInitialize()        XtAppInitialize()        R3
  1187. XtMainLoop()        XtAppMainLoop()            R3
  1188. MenuPopdown(action)    XtMenuPopdown(action)        R4
  1189. MenuPopup(action)    XtMenuPopup(action)        R4
  1190. XtNextEvent()        XtAppNextEvent()        R3
  1191. XtPeekEvent()        XtAppPeekEvent()        R3
  1192. XtPending()        XtAppPending()            R3
  1193. XtSetErrorHandler()    XtAppSetErrorHandler()        R3
  1194. XtSetErrorMsgHandler    XtAppSetErrorMsgHandler()    R3
  1195. XtSetSelectionTimeout()    XtAppSetSelectionTimeout()    R3
  1196. XtSetWarningHandler()    XtAppSetWarningHandler()    R3
  1197. XtSetWarningMsgHandler() XtAppSetWarningMsgHandler()    R3
  1198. XtWarning()        XtAppWarning()            R3
  1199. XtWarningMsg()        XtAppWarningMsg()        R3
  1200.  
  1201. ----------------------------------------------------------------------
  1202. Subject: 20. Where are the resources loaded from?
  1203. ----------------------------------------------------------------------
  1204.  
  1205. The resources of a widget are filled in from the following places
  1206. (from highest priority to lowest priority):
  1207.  
  1208.     1. Args passed at creation time.
  1209.     2. Command line arguments.
  1210.     3. User's per host defaults file
  1211.     4. User's defaults file.
  1212.     5. User's per application default file.
  1213.     6. System wide per application default file.
  1214.  
  1215. Note that 2-6 are read only once on application startup.  The result
  1216. of steps 3-6 is a single resource database used for further queries.
  1217.  
  1218. The per host defaults file contains customizations for all
  1219. applications executing on a specific computer.  This file is either
  1220. specified with the XENVIRONMENT environment variable or if that is not
  1221. set then the file $HOME/.Xdefaults-<host> is used.
  1222.  
  1223. The user defaults file is either obtained from the RESOURCE_MANAGER
  1224. property on the root window of the display or if that is not set then
  1225. the file $HOME/.Xdefaults is used.  Typically, the program "xrdb" is
  1226. used to set the RESOURCE_MANAGER property.  Please note that this
  1227. should be kept relatively small as each client that connects to the
  1228. display must transfer the property.  A size of around 1-3KByte is
  1229. reasonable.  Some toolkits may track changes to the RESOURCE_MANAGER
  1230. but most do not.
  1231.  
  1232. A user may have many per application default files containing
  1233. customizations specific to each application.  The intrinsics are quite
  1234. flexible on how this file is found.  Read the next part that describes
  1235. the various environment variables and how they effect where this file
  1236. is found.
  1237.  
  1238. The system wide per application default files are typically found in
  1239. /usr/lib/X11/app-defaults.  If such a file is not found then the
  1240. fallback resources are used.  The intrinsics are quite flexible on how
  1241. this file is found.  Read the next part that describes the various
  1242. environment variables and how they effect where this file is found.
  1243.  
  1244. [Thanks to Oliver Jones (oj@pictel.com) for the following, 6/92]
  1245.  
  1246. You can use several environment variables to control how resources are
  1247. loaded for your Xt-based programs -- XFILESEARCHPATH,
  1248. XUSERFILESEARCHPATH, and XAPPLRESDIR.  These environment variables
  1249. control where Xt looks for application-defaults files as an
  1250. application is initializing.  Xt loads at most one app-defaults file
  1251. from the path defined in XFILESEARCHPATH and another from the path
  1252. defined in XUSERFILESEARCHPATH.
  1253.  
  1254. Set XFILESEARCHPATH if software is installed on your system in such a
  1255. way that app-defaults files appear in several different directory
  1256. hierarchies.  Suppose, for example, that you are running Sun's Open
  1257. Windows, and you also have some R4 X applications installed in
  1258. /usr/lib/X11/app-defaults. You could set a value like this for
  1259. XFILESEARCHPATH, and it would cause Xt to look up app-defaults files
  1260. in both /usr/lib/X11 and /usr/openwin/lib (or wherever your
  1261. OPENWINHOME is located):
  1262.  
  1263.     setenv XFILESEARCHPATH /usr/lib/X11/%T/%N:$OPENWINHOME/lib/%T/%N
  1264.  
  1265. The value of this environment variable is a colon-separated list of
  1266. pathnames.  The pathnames contain replacement characters as follows
  1267. (see XtResolvePathname()):
  1268.  
  1269.     %N    The value of the filename parameter, or the
  1270.         application's class name.
  1271.     %T    The value of the file "type".  In this case, the
  1272.         literal string "app-defaults"
  1273.     %C    customization resource (R5 only)
  1274.     %S    Suffix.  None for app-defaults.
  1275.     %L    Language, locale, and codeset (e.g. "ja_JP.EUC")
  1276.     %l    Language part of %L  (e.g. "ja")
  1277.     %t    The territory part of the display's language string
  1278.     %c    The codeset part of the display's language string
  1279.  
  1280. Let's take apart the example.  Suppose the application's class name is
  1281. "Myterm". Also, suppose Open Windows is installed in /usr/openwin.
  1282. (Notice the example omits locale-specific lookup.)
  1283.  
  1284.     /usr/lib/X11/%T/%N        means /usr/lib/X11/app-defaults/Myterm
  1285.     $OPENWINHOME/lib/%T/%N    means /usr/openwin/lib/app-defaults/Myterm
  1286.  
  1287. As the application initializes, Xt tries to open both of the above
  1288. app-defaults files, in the order shown.  As soon as it finds one, it
  1289. reads it and uses it, and stops looking for others.  The effect of
  1290. this path is to search first in /usr/lib/X11, then in /usr/openwin.
  1291.  
  1292. Let's consider another example. This time, let's set
  1293. XUSERFILESEARCHPATH so it looks for the file Myterm.ad in the current
  1294. working directory, then for Myterm in the directory ~/app-defaults.
  1295.  
  1296.     setenv XUSERFILESEARCHPATH ./%N.ad:$HOME/app-defaults/%N
  1297.  
  1298. The first path in the list expands to ./Myterm.ad.  The second expands
  1299. to $HOME/app-defaults/Myterm.  This is a convenient setting for
  1300. debugging because it follows the Imake convention of naming the
  1301. app-defaults file Myterm.ad in the application's source directory, so
  1302. you can run the application from the directory in which you are
  1303. working and still have the resources loaded properly.
  1304.  
  1305. NOTE: when looking for app-default files with XUSERFILESEARCHPATH,
  1306.       for some  bizarre reason, neither the type nor file suffix is
  1307.       defined so %T and %S are useless.
  1308.  
  1309. With R5, there's another twist.  You may specify a customization
  1310. resource value.  For example, you might run the "myterm" application
  1311. like this:
  1312.  
  1313.     myterm -xrm "*customization: -color"
  1314.  
  1315. If one of your pathname specifications had the value
  1316. "/usr/lib/X11/app-defaults/%N%C" then the expanded pathname would be
  1317. "/usr/lib/X11/app-defaults/Myterm-color" because the %C substitution
  1318. character takes on the value of the customization resource.
  1319.  
  1320. The default XFILESEARCHPATH, compiled into Xt, is:
  1321.  
  1322.         /usr/lib/X11/%L/%T/%N%C:\  (R5)
  1323.         /usr/lib/X11/%l/%T/%N%C:\  (R5)
  1324.         /usr/lib/X11/%T/%N%C:\     (R5)
  1325.         /usr/lib/X11/%L/%T/%N:\
  1326.         /usr/lib/X11/%l/%T/%N:\
  1327.         /usr/lib/X11/%T/%N
  1328.  
  1329. (Note: some sites replace /usr/lib/X11 with a ProjectRoot in this
  1330. batch of default settings.)
  1331.  
  1332. The default XUSERFILESEARCHPATH, also compiled into Xt, is 
  1333.  
  1334.         <root>/%L/%N%C:\  (R5)
  1335.         <root>/%l/%N%C:\  (R5)
  1336.         <root>/%N%C:\     (R5)
  1337.         <root>/%L/%N:\
  1338.         <root>/%l/%N:\
  1339.         <root>/%N:
  1340.  
  1341. <root> is either the value of XAPPLRESDIR or the user's home directory
  1342. if XAPPLRESDIR is not set.  If you set XUSERFILESEARCHPATH to some
  1343. value other than the default, Xt ignores XAPPLRESDIR altogether.
  1344.  
  1345. Notice that the quick and dirty way of making your application find
  1346. your app-defaults file in your current working directory is to set
  1347. XAPPLRESDIR to ".", a single dot.  In R3, all this machinery worked
  1348. differently; for R3 compatibilty, many people set their XAPPLRESDIR
  1349. value to "./", a dot followed by a slash.
  1350.  
  1351.  
  1352. ----------------------------------------------------------------------
  1353. Subject: 21. What order are callbacks executed in?
  1354. ----------------------------------------------------------------------
  1355. (Courtesy of Donna Converse, converse@x.org; 5/10/92)
  1356.  
  1357. The Intrinsics library do not guarantee an order.  This is because
  1358. both the widget writer and the application writer have the ability to
  1359. modify the entire contents of the callback list.  Neither one
  1360. currently knows what the other is doing and so the Intrinsics cannot
  1361. guarantee the order of execution.
  1362.  
  1363. The application programmer cannot rely on the widget writer; the
  1364. widget writer is not required to document when the widget will add and
  1365. remove callbacks from the list or what effect this will have;
  1366. therefore the functionality contained in a callback should be
  1367. independent of the functionality contained in other callbacks on the
  1368. list.
  1369.  
  1370. Even though the Xt standard in the definition of XtAddCallback
  1371. says:
  1372.  
  1373.      "callback_name: Specifies the callback list to which the
  1374.      procedure is to be appended."
  1375.  
  1376. you may not infer from the word "appended" that the callback routines
  1377. are called in the same order as they have been added to the callback
  1378. list.
  1379.  
  1380. ----------------------------------------------------------------------
  1381. Subject: 22. How do I know if a widget is visible?
  1382. ----------------------------------------------------------------------
  1383. (Courtesy of Donna Converse, converse@x.org; 5/14/92)
  1384.  
  1385. > I am building a widget needs to know if it is visible. I set the visible
  1386. > interest field in Core and if my window is completely obscured, the Core
  1387. > visible flag goes FALSE. However, if my window is iconified, the flag
  1388. > stays set to TRUE.
  1389.  
  1390. Right, everything is implemented correctly.  This demonstrates a "deficiency"
  1391. in the X protocol, and the Core widget is reflecting the capabilities of the
  1392. protocol.  (The "deficiency" is that the information is available in one way,
  1393. in this case an inconvenient way.)  The Xt specification is accurate, in
  1394. the second and third paragraphs of section 7.10.2, so read this section
  1395. carefully.  The visible field will not change in response to iconification.
  1396.  
  1397. A VisibilityNotify event will not be received when the window goes from
  1398. viewable to unviewable, that is, when the widget or an ancestor is unmapped;
  1399. that is, when iconification occurs.  This is the protocol deficiency.
  1400. Visibility state and viewable state have specific meanings in the X protocol;
  1401. see the glossary in your Xlib and X protocol reference manual.
  1402.  
  1403. > Is this a problem with "mwm" or is there something
  1404. > else which needs to be done?
  1405.  
  1406. You'll see this with any window manager, with no window manager.
  1407.  
  1408. > If the problem is "mwm", what is the fastest
  1409. > way to determine if a window is iconified? 
  1410.  
  1411. As an application writer, keep track with a global Boolean in an action
  1412. routine with translations for MapNotify and UnmapNotify on the Shell widget
  1413. which contains your custom widget.  As the custom widget writer, see the
  1414. map_state field returned by a call to XGetWindowAttributes.  These are
  1415. suggestions.
  1416.  
  1417. ----------------------------------------------------------------------
  1418. Subject: 23. How do I reparent a widget in Xt, i.e. XtReparentWidget()?
  1419. ----------------------------------------------------------------------
  1420.  
  1421. You can't.
  1422.  
  1423. ----------------------------------------------------------------------
  1424. Subject: 24. Why use XtMalloc, XtFree, etc?
  1425. ----------------------------------------------------------------------
  1426.  
  1427. Unfortunately, most code that calls malloc(), realloc() or calloc()
  1428. tends to ignore the possibility of returning NULL.  At best it is
  1429. handled something like:
  1430.  
  1431.     ptr = (type *) malloc (sizeof (type))
  1432.     if (!ptr)
  1433.     {
  1434.         perror ("malloc in xyzzy()");
  1435.         exit (1)
  1436.     }
  1437. To handle this common case the Intrinsics define the functions
  1438. XtMalloc(), XtCalloc(), XtNew(), XtNewString() and XtRealloc() which
  1439. all use the standard C language functions malloc(), calloc() and
  1440. realloc() but execute XtErrorMsg() if a NULL value is returned.  Xt
  1441. error handlers are not supposed to return so this effectively exits.
  1442.  
  1443. In addition, if XtRealloc() is called with a NULL pointer, it uses
  1444. XtMalloc() to get the initial space.  This allows code like:
  1445.  
  1446.     if (!ptr)
  1447.         ptr = (type *) malloc (sizeof (type));
  1448.     else
  1449.         ptr = (type *) realloc (ptr, sizeof (type) * (count + 1));
  1450.     ++count;
  1451.  
  1452. to be written as:
  1453.  
  1454.     ptr = XtRealloc (ptr, sizeof (ptr) * ++count);
  1455.  
  1456. Also, XtFree() accepts a NULL pointer as an argument.  Generally, I've
  1457. found the Xt functions conveniant to use.  However, anytime I'm
  1458. allocating anything potentially large I use the standard functions so
  1459. I can fully recover from not enough memory errors.
  1460.  
  1461. XtNew() and XtNewString() are conveniant macros for allocating a
  1462. structure or copying a string:
  1463.  
  1464.       struct abc *xyzzy;
  1465.       char         *ptr;
  1466.       char         *str = "abcdef";
  1467.  
  1468.       xyzzy = XtNew (struct abc);    /* takes care of type casting */
  1469.       ptr = XtNewString (str);
  1470.  
  1471. A strict interpretation of the Intrinsics reference manual allow an
  1472. implementation to provide functions that are not exchangable with
  1473. malloc() and free().  I.e. code such as:
  1474.  
  1475.      char          *ptr;
  1476.  
  1477.      ptr = XtMalloc (100);
  1478.      /* ... */
  1479.      free (ptr);
  1480.  
  1481. may not work.  Personally, I'd call any implementation that did this
  1482. broken and complain to the vendor.
  1483.  
  1484. A common error for Motif programmers is to use XtFree() on a string
  1485. when they should really be using XmStringFree().
  1486.  
  1487. ----------------------------------------------------------------------
  1488. Subject: 25. How to debug an Xt application?
  1489. ----------------------------------------------------------------------
  1490. First, I'd recomend getting "purify" from Pure Software.  This is a
  1491. great package for tracing memory problems on Sun's.  It's a bit pricey
  1492. at $2750 but I'd still recomend it.  Excuse the marketing blurb
  1493. (contact support@pure.com for more info).
  1494.  
  1495.     Purify inserts additional checking instructions directly into
  1496.     the object code produced by existing compilers.  These
  1497.     instructions check every memory read and write performed by
  1498.     the program under test and detect several types of access
  1499.     errors, such as reading unitialized memory, writing past
  1500.     malloc'd bounds, or writing to freed memory.  Purify inserts
  1501.     checking logic into all of the code in a program, including
  1502.     third party and vendor object-code libraries, and verifies
  1503.     system call interfaces.  In addition, Purify tracks memory
  1504.     usage and identifies individual memory leaks using a novel
  1505.     adaption of garbage collection techniques.  Purify's nearly
  1506.     comprehensive memory access checking slows the target program
  1507.     down typically by a factor of two to five.
  1508.  
  1509. An alternative package that isn't as pricey ($395 for a Sun), runs on
  1510. many Unix's and has pretty similar features is "The SENTINEL Debugging
  1511. Environment".  This replaces malloc() and several other C library
  1512. functions to add additional checks.  (contact cpcahil@virtech.vti.com
  1513. for more info)
  1514.  
  1515. Next, if you are getting any sort of Xlib error, you'll need to run in
  1516. synchronous mode, easily accomplished with the "-sync" command line
  1517. argument or by setting the variable Xdebug to 1 with your debugger.  Then
  1518. set a break point in exit().  This will let you trace back to the
  1519. original Xlib function being called.  If you don't run in synchronous
  1520. mode, then the actual error may have occured any number of calls to
  1521. Xlib previously since the Xlib calls are buffered and replies from the
  1522. server are asynchronous.
  1523.  
  1524. Next, if you are having trouble with window layout, you can use the
  1525. undocumented resource "xtIdentifyWindows" or the class resource
  1526. "XtDebug" to cause the widget name to be identified with each window.
  1527. For example:
  1528.  
  1529.     example% xload -xrm '*XtDebug:true' &
  1530.     example% xwininfo -tree
  1531.          <click in new xload window>
  1532.  
  1533. will give the normal information but the widget name and class of each
  1534. window is included.  This can help for checking the location and size
  1535. of errant widgets.
  1536.  
  1537. Next, if you are having trouble with geometry managers or you want to
  1538. test the way a widget manages it's children, you can try
  1539. ftp.x.org:contrib/libXtGeo.tar.Z.  This acts as a filter
  1540. between any children and a geometry manager and checks the behaviour
  1541. of both.  It's a very clever idea.
  1542.  
  1543. The most unfortunate problem is debugging a callback while the
  1544. application is executing a grab of the keyboard or mouse (such as from
  1545. a pulldown menu).  The server effectively locks up and you'll need to
  1546. go to another machine and kill the debugger manually.  The server
  1547. locks up because the application being debugged has said no one else
  1548. can have access to the keyboard but the application is not stopped
  1549. waiting because the debugger is waiting for your commands.
  1550. Unfortunately you can't give them because all the input is going to
  1551. your application which is stopped.
  1552.  
  1553. The best way to debug this kind of problem is with two machines on
  1554. your desk, running the program under a debugger (or other environment)
  1555. on one machine, and running the application on the other, possibly
  1556. using a command sequence like this:
  1557.  
  1558.     othermachine% xhost +thismachine
  1559.     thismachine% setenv DISPLAY othermachine:0;
  1560.     thismachine% gdb application    # Your favorite debugger.
  1561.     or this:
  1562.     othermachine% xhost +thismachine
  1563.     thismachine% gdb application
  1564.     (gdb) set environment DISPLAY othermachine:0
  1565.     (gdb) run ...
  1566.  
  1567. I believe CodeCenter, a C interpreter/graphical debugger has a method
  1568. of dealing with this by explicitely calling the Xlib functions to
  1569. release any grabs during breakpoints.
  1570.  
  1571. Debugging widget problems requires pretty good debugging skills and
  1572. knowledge of how widgets work.  You can go a long way without knowing
  1573. the internals of a particular widget but not very far without
  1574. understanding how a widget works.  Judicious use of conditional
  1575. breakpoints and adding print statements with the debugger help a great
  1576. deal.
  1577.  
  1578. ----------------------------------------------------------------------
  1579. Subject: 26. Why don't XtAddInput(), XtAddTimeout() and XtAddWorkProc() work?
  1580. ----------------------------------------------------------------------
  1581.    I have got a delicate problem with the three routines XtAddInput,
  1582.    XtAddTimeOut and XtAddWorkProc. The problem I have is that when
  1583.    I use them in my application they seem not to be registred properly.
  1584.    I have made a handy little testprogram where everything works
  1585.    perfect, but in my "real" application nothing happens. 
  1586.  
  1587. The introduction in R3 of the XtApp*() functions obsoleted those
  1588. routines (see Q19 for other changes in R3, R4, and R5).  What happens is
  1589. they use a default application context different then the one you may
  1590. have created.  Since events and timeouts are distributed on a per
  1591. application context basis and you are using two application contexts,
  1592. you won't get those events.
  1593.  
  1594. For example:
  1595.  
  1596.     ...
  1597.     cnt = 0;
  1598.     toplevel = XtAppInitialize(&app, class,
  1599.                    Desc, XtNumber (Desc),
  1600.                    &argc, argv,
  1601.                    Fallback, args, cnt);
  1602.  
  1603.     XtAddTimeOut (...)
  1604.     XtAddWorkProc (...)
  1605.  
  1606.     XtAppMainLoop (app)
  1607.  
  1608. would never invoke the timeout.
  1609.  
  1610. ----------------------------------------------------------------------
  1611. Subject: 27. What is and how can I implement drag and drop?
  1612. ----------------------------------------------------------------------
  1613. (Courtesy of Roger Reynolds, rogerr@netcom.com; 19 Feb 93)
  1614.  
  1615. Drag-n-drop is a buzzword for moving data between clients, in an
  1616. ``intuitive'' fashion.
  1617.  
  1618. Motif Version 1.2 supports drag-n-drop capabilities, OpenLook has
  1619. supported d-n-d all along.  The two protocols are not compatable with
  1620. each other, and so far as I know, they are not published.
  1621.  
  1622. I wrote a package called RDD which is designed to be a flexible public
  1623. protocol for doing drag 'n drop operations between clients.  My
  1624. intention was to provide a tool which would make it easy for people to
  1625. support a "standard" drag-n-drop protocol in the programs they develop
  1626. and contribute or sell, regardless of what widget set is used (as long
  1627. as it is based on Xt).
  1628.  
  1629. The implementation is based upon my understanding of the ICCCM
  1630. conventions, for more details read the code.
  1631.  
  1632. I have heard from dozens of people using RDD who like it and feel that
  1633. it works a whole lot better than Motif 1.2 stuff.  Also, there seem to
  1634. be many who think that it is neat but are constrained to use Motif
  1635. anyway.
  1636.  
  1637. The latest RDD (and some other stuff) is available for ftp from
  1638. netcom.com, in /pub/rogerr.  A (possibly older) version is also
  1639. available on ftp.x.org in /contrib.
  1640.  
  1641. ----------------------------------------------------------------------
  1642. Subject: 28. How can I add a C++ member function as a widget callback?
  1643. ----------------------------------------------------------------------
  1644. (Courtesy of lanzo@tekelec.com (Mark Lanzo), 7 Sep 1993)
  1645.  
  1646. You can not add a regular C++ member function as a callback to a 
  1647. widget, because the callback function won't be invoked with the
  1648. hidden object pointer "this" which all regular C++ member functions
  1649. require.  However, there is a way to get around this limitation:
  1650. "static" member functions.
  1651.  
  1652. A static member function is a function to which the usual scoping
  1653. and access rules apply, but which is not in fact actually associated
  1654. with a specific instance of an object, and it is NOT called using the 
  1655. special member function calling syntax.  In particular, there is no 
  1656. "this" pointer supplied to the function.  This means that a "static"
  1657. member function is really a lot like a "friend" function except that
  1658. its name is within the scope of the class (in other words, the name
  1659. is prefixed with the class name).
  1660.  
  1661. To demonstrate this, let's create a trivial class "Icon" which includes
  1662. a "button" widget, and a member function "select_CB" which is
  1663. installed as the "XmNselectCallback" on the button.  The class
  1664. declaration would then look something like this:
  1665.  
  1666.     class Icon
  1667.     {
  1668.     private:
  1669.             Widget      button;
  1670.             static void select_CB(Widget, XtPointer, XtPointer);
  1671.  
  1672.     public:
  1673.             Icon(Widget parent);        // Constructor
  1674.     };
  1675.  
  1676. For the example above, I can declare the constructor and callback
  1677. functions like this:
  1678.  
  1679.     Icon::Icon (Widget parent)
  1680.     {
  1681.         button = XtVaCreateWidget ("icon_button", xmPushButtonWidgetClass,
  1682.                       parent, NULL);
  1683.  
  1684.         //  Depending on your compiler, you may be able to specify
  1685.         //  "&Icon::select_CB" simply as "select_CB" in the 
  1686.         //  following statement:
  1687.         XtAddCallback (button,  XmNselectCallback, &Icon::select_CB,
  1688.               (XtPointer) this);
  1689.     }
  1690.  
  1691.     void Icon::select_CB (Widget w, XtPointer userData, XtPointer callData)
  1692.     {
  1693.         Icon * icon = (Icon *) userData;        // Instead of "this"
  1694.  
  1695.             // do whatever you want to do when the icon is selected ...
  1696.     }
  1697.  
  1698. There are two things to note here:
  1699.  
  1700.  *) If you want the static member function to work on a specific 
  1701.     object, you must supply the object pointer (such as by "userData"
  1702.     in the example).  Just like a non-member function.
  1703.  
  1704.  *) Although the function is declared as "static" inside the class
  1705.     definition, you do NOT include the "static" keyword when you
  1706.     actually define the function.
  1707.  
  1708. ----------------------------------------------------------------------
  1709. Subject: 29. How can I identify the children of a manager widget?
  1710. ----------------------------------------------------------------------
  1711.  
  1712. Use XtGetValues() on XtNchildren (array of widget IDs) and
  1713. XtNnumChildren (number of widgets in array).
  1714.  
  1715.     Widget        *children = NULL;
  1716.     Cardinal    count = 0;
  1717.     Arg        args[10];
  1718.     Cardinal    cnt;
  1719.  
  1720.     cnt = 0;
  1721.     XtSetArg (args[cnt], XtNchildren, &children); ++cnt;
  1722.     XtSetArg (args[cnt], XtNnumChildren, &count); ++cnt;
  1723.     XtGetValues (widget, args, cnt);
  1724.  
  1725. NOTE: This does not get the list of popup children.  One must access
  1726. the private members of Core to do so.
  1727.  
  1728. ----------------------------------------------------------------------
  1729. Subject: 30. Can I use XtMoveWidget(), ... to move widgets I created?
  1730. ----------------------------------------------------------------------
  1731.  
  1732. No.  In general, XtMoveWidget(), XtResizeWidget(),
  1733. XtMakeGeometryRequest(), and XtConfigureWidget() are for widget
  1734. internals only.  The only way for applications to change widget
  1735. geometry or configuration is through the XtSetValues() interface and
  1736. setting the XtNx, XtNy, XtNwidth and XtNheight resources.  If this
  1737. interface does not give you what you want, you should subclass the
  1738. widget to modify its geometry managers.
  1739.  
  1740. ----------------------------------------------------------------------
  1741. Subject: 31. Why is XtGetValues() on XtNx, XtNy of my top level shell wrong?
  1742. ----------------------------------------------------------------------
  1743.  
  1744. XtNx and XtNy are the coordinates relative to your shell's parent
  1745. window, which is usually a window manager's frame window.  To
  1746. translate to the root coordinate space, use XtTranslateCoords() or
  1747. XTranslateCoordinates().
  1748.  
  1749. NOTE: XtTranslateCoords() was broken in releases prior to R4.
  1750.  
  1751. ----------------------------------------------------------------------
  1752. Subject: 32. Why do some people use XmN<something> as resource names?
  1753. ----------------------------------------------------------------------
  1754.  
  1755. Motif adopted the convention of prefixing all their resources with
  1756. XmN instead of XtN.  Why?  It makes some small amount of sense to not
  1757. pollute the Xt name space.  Unfortunately it is not really practical
  1758. because it means every widget set would have to define all the
  1759. resources, including ones defined by the Intrinsics.  Very messy.  But
  1760. heh, OSF is it's own world, right?
  1761.  
  1762. ----------------------------------------------------------------------
  1763. Subject: 33. How do I make my life easier when designing an application?
  1764. ----------------------------------------------------------------------
  1765.  
  1766. Find out about WCL.  Any other suggestions, anyone?
  1767.  
  1768. ----------------------------------------------------------------------
  1769. Subject: 34. Why can't I override translations? Only the first item works.
  1770. ----------------------------------------------------------------------
  1771. (Thanks to Timothy J. Horton, 5/91)
  1772.  
  1773. You probably have an extra space after the specification of the first 
  1774. item, like this:
  1775.     basic*text.translations:  #override \
  1776.     Ctrl<Key>a:    beginning-of-line() \n\     
  1777.     Ctrl<Key>e:    end-of-line()
  1778.                           ^ extra space
  1779. The newline after that space is ending the translation definition.
  1780.  
  1781. ----------------------------------------------------------------------
  1782. Subject: 35. Why do I get "Warning: Widget class version mismatch"?
  1783. ----------------------------------------------------------------------
  1784.  
  1785. This error, which typically goes on to say, "widget 11004 vs.
  1786. intrinsics 11003" indicates that the header files you included when
  1787. building your program didn't match the header files that the Xt
  1788. library you're linking against was built with; check your -I include
  1789. path and -L link-path to be sure.
  1790.  
  1791. However, the problem also occurs when linking against a version of the
  1792. X11R4 Xt library before patch 10; the version number was wrong.  Some
  1793. Sun OW systems, in particular, were shipped with the flawed version of
  1794. the library, and applications which link against the library typically
  1795. give the warnings you have seen.
  1796.  
  1797. ----------------------------------------------------------------------
  1798. Subject: 36. Where can I get a good file-selector widget?
  1799. ----------------------------------------------------------------------
  1800.  
  1801. The Free Widget Foundation set offers a FileSelector widget, with
  1802. separate directory path and file listing windows, and the
  1803. FileComplete, which has emacs-style file completion and ~ expansion.
  1804.  
  1805. Other available file-requestor widgets include the XiFileSelector from
  1806. Iris Software's book, the xdbx file-selector extracted by David Nedde
  1807. (daven@ivy.wpi.edu), and the FileNominator from the aXe distribution.
  1808.  
  1809. The GhostView, Xfig, and vimage packages also include file-selector
  1810. widgets.
  1811.  
  1812. ----------------------------------------------------------------------
  1813. Subject: 37. Where can I find a hypertext widget or source code?
  1814. ----------------------------------------------------------------------
  1815.  
  1816. A hypertext widget was posted to comp.sources.x.  It can be found in
  1817. volume 16 of the archives at ftp.uu.net under the name "hman".  The
  1818. distribution includes a hypertext widget with both Athena and Motif
  1819. compatability (set at compile-time) and hman, a Motif-based man reference page
  1820. reader that uses the widget to look up other man topics.  [Joe Shelby
  1821. (shelby@dirac.physics.jmu.edu); 6/93]
  1822.  
  1823. ----------------------------------------------------------------------
  1824. Subject: 38. What widget is appropriate to use as a drawing canvas?
  1825. ----------------------------------------------------------------------
  1826.  
  1827. Some widget sets have a widget particularly for this purpose -- a
  1828. WorkSpace or DrawingArea which doesn't display anything but lets your Xt 
  1829. application know when it has been re-exposed, resized, and when it has received
  1830. user key and mouse input. 
  1831.  
  1832. The best thing to do for other widget sets -- including the Athena set 
  1833. -- is to create or obtain such a widget; this is preferable to drawing into a 
  1834. core widget and grabbing events with XtAddEventHandler(), which loses a number 
  1835. of benefits of Xt and encapsulation of the functionality .  
  1836.  
  1837. The publicly-available programs xball and xpic include other versions. 
  1838. The Display widget in the XG library (libXG-2.0.tar.Z on ftp.x.org) provides a 
  1839. generic way of drawing graphics in a widget.
  1840.  
  1841. The Athena Widget manual (mit/doc/Xaw/Template in the R5 distribution) 
  1842. includes a tutorial and source code to a simple widget which is suitable for 
  1843. use. 
  1844.  
  1845. The Free Widget Foundation set contains a Canvas widget.
  1846.  
  1847. ----------------------------------------------------------------------
  1848. Subject: 39.!What is this link problem with _get_wmShellWidgetClass?
  1849. ----------------------------------------------------------------------
  1850.  
  1851. Unresolved externals under SunOS 4.1.[23] is indicative of an incorrect 
  1852. configuration, specifically failure to set the OSTeenyVersion in sun.cf.
  1853.  
  1854. If you are running on SunOS 4.1.[23] you should apply all the fixes up
  1855. to fix-25. Make certain that you set the OSTeenyVersion correctly in 
  1856. mit/config/sun.cf.
  1857.  
  1858. [Above from kaleb@expo.lcs.mit.edu (Kaleb Keithley) 15 Oct 1993]
  1859.  
  1860. In SunOS 4.1.2 Sun fixed a shared-library bug in ld which conflicts
  1861. with the way X builds the shared Xmu library, causing these symbols,
  1862. notably, to be undefined when building some X11 clients:
  1863.  
  1864.     _get_wmShellWidgetClass
  1865.     _get_applicationShellWidgetClass
  1866.  
  1867. Compiling "-Bstatic -lXmu -Bdynamic" appears to work. 
  1868.  
  1869. To solve the problem if you are using OpenWindows 3.0 (X11R4-based
  1870. Xt), please contact your local Sun office and request the following
  1871. patches:
  1872.  
  1873. Patch i.d.      Description
  1874. 100512-02       4.1.x OpenWindows 3.0 libXt Jumbo patch
  1875. 100573-03       4.1.x OpenWindows 3.0 undefined symbols when using
  1876.                         shared libXmu
  1877.  
  1878. [Greg Earle, earle@Sun.COM; 7/92] 
  1879.  
  1880. A source patch for use with the MIT X11R4 libraries was developed by
  1881. Conrad Kimball (cek@sdc.boeing.com); it retrofits into R4 some fixes
  1882. made in R5 to get around this problem. The patch is on ftp.x.org in
  1883. [1/93] contrib/X11R4_sunos4.1.2_patch_version3.Z
  1884.  
  1885. ----------------------------------------------------------------------
  1886. Subject: 40. Why does XtGetValues not work for me (sic)?
  1887. ----------------------------------------------------------------------
  1888.  
  1889. The XtGetValues interface for retrieving resources from a widget is
  1890. sensitive to the type of variable. Your code may be doing something like this:
  1891.  
  1892.     {
  1893.     Arg args[3];
  1894.     int i;
  1895.     int sensitive;        /* oops; wrong data type */
  1896.     i=0;
  1897.     XtSetArg (args[i], XtNsensitive, &sensitive); i++;
  1898.     XtGetValues(widget, args, i );
  1899.     ...
  1900.     }
  1901.  
  1902. But XtNsensitive is a Boolean, which on most machines is a single byte; 
  1903. declaring the variable "sensitive" as Boolean works properly. This problem 
  1904. comes up often when using particular toolkits that redefine the Xt types 
  1905. Dimension and Position; code that assumes they are int will have similar 
  1906. problems if those types are actually short. In general: you are safe if you
  1907. use the actual type of the resource, as it appears in the widget's man page.
  1908. [11/90]
  1909.  
  1910. ----------------------------------------------------------------------
  1911. Subject: 41. Is this a memory leak in the X11R4 XtDestroyWidget()?!
  1912. ----------------------------------------------------------------------
  1913.  
  1914. Yes. This is the "unofficial" fix-19 for the X11R4 Destroy.c:
  1915.  
  1916. *** Destroy.c.1.37    Thu Jul 11 15:41:25 1991
  1917. --- lib/Xt/Destroy.c    Thu Jul 11 15:42:23 1991
  1918. ***************
  1919. *** 1,4 ****
  1920. --- 1,5 ----
  1921.   /* $XConsortium: Destroy.c,v 1.37 90/09/28 10:21:32 swick Exp $ */
  1922. + /* Plus unofficial patches in revisions 1.40 and 1.41 */
  1923.   
  1924.   /***********************************************************
  1925.   Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  1926. ***************
  1927. *** 221,239 ****
  1928.        */
  1929.   
  1930.       int i = 0;
  1931. !     DestroyRec* dr = app->destroy_list;
  1932.       while (i < app->destroy_count) {
  1933.       if (dr->dispatch_level >= dispatch_level)  {
  1934.           Widget w = dr->widget;
  1935.           if (--app->destroy_count)
  1936.           bcopy( (char*)(dr+1), (char*)dr,
  1937. !                app->destroy_count*sizeof(DestroyRec)
  1938.                 );
  1939.           XtPhase2Destroy(w);
  1940.       }
  1941.       else {
  1942.           i++;
  1943. -         dr++;
  1944.       }
  1945.       }
  1946.   }
  1947. --- 222,245 ----
  1948.        */
  1949.   
  1950.       int i = 0;
  1951. !     DestroyRec* dr;
  1952.       while (i < app->destroy_count) {
  1953. +     /* XtPhase2Destroy can result in calls to XtDestroyWidget,
  1954. +      * and these could cause app->destroy_list to be reallocated.
  1955. +      */
  1956. +     dr = app->destroy_list + i;
  1957.       if (dr->dispatch_level >= dispatch_level)  {
  1958.           Widget w = dr->widget;
  1959.           if (--app->destroy_count)
  1960.           bcopy( (char*)(dr+1), (char*)dr,
  1961. !                (app->destroy_count - i) * sizeof(DestroyRec)
  1962.                 );
  1963.           XtPhase2Destroy(w);
  1964.       }
  1965.       else {
  1966.           i++;
  1967.       }
  1968.       }
  1969.   }
  1970.  
  1971. [from Donna Converse, converse@x.org]
  1972.  
  1973. ----------------------------------------------------------------------
  1974. Subject: 42. Is this a memory leak in the X11R4 deletion of work procs?!
  1975. ----------------------------------------------------------------------
  1976.  
  1977. Apparently the X11R4 NextEvent.c`CallWorkProc fails to properly replace
  1978. the work proc record back on the free list correctly.
  1979.  
  1980.         if (delete) {
  1981.             w->next = freeWorkRecs;
  1982.             freeWorkRecs = w->next;    /* should be  =w; */
  1983.         }
  1984.  
  1985. ----------------------------------------------------------------------
  1986. Subject: 43. How do I query the user synchronously using Xt?
  1987. ----------------------------------------------------------------------
  1988.     
  1989. It is possible to have code which looks like this trivial callback,
  1990. which has a clear flow of control. The calls to AskUser() block until
  1991. answer is set to one of the valid values. If it is not a "yes" answer,
  1992. the code drops out of the callback and back to an event-processing
  1993. loop:
  1994.  
  1995.     void quit(Widget w, XtPointer client, XtPointer call)
  1996.     {
  1997.         int             answer;
  1998.         answer = AskUser(w, "Really Quit?");
  1999.         if (RET_YES == answer)
  2000.             {
  2001.             answer = AskUser(w, "Are You Really Positive?");
  2002.             if (RET_YES == answer)
  2003.                 exit(0);
  2004.                 }
  2005.     }
  2006.  
  2007. A more realistic example might ask whether to create a file or whether
  2008. to overwrite it.
  2009.  
  2010. This is accomplished by entering a second event-processing loop and
  2011. waiting until the user answers the question; the answer is returned to
  2012. the calling function. That function AskUser() looks something like
  2013. this, where the Motif can be replaced with widget-set-specific code to
  2014. create some sort of dialog-box displaying the question string and
  2015. buttons for "OK", "Cancel" and "Help" or equivalents:
  2016.  
  2017.   int AskUser(w, string)
  2018.         Widget          w;
  2019.         char           *string;
  2020.   {
  2021.         int             answer=RET_NONE;    /* some not-used marker */
  2022.         Widget          dialog;            /* could cache&carry, but ...*/
  2023.         Arg             args[3];
  2024.         int             n = 0;
  2025.         XtAppContext    context;
  2026.  
  2027.         n=0;
  2028.         XtSetArg(args[n], XmNmessageString, XmStringCreateLtoR(string,
  2029.                 XmSTRING_DEFAULT_CHARSET)); n++;
  2030.         XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  2031.         dialog = XmCreateQuestionDialog(XtParent(w), string, args, n);
  2032.         XtAddCallback(dialog, XmNokCallback, response, &answer);
  2033.         XtAddCallback(dialog, XmNcancelCallback, response, &answer);
  2034.         XtAddCallback(dialog, XmNhelpCallback, response, &answer);
  2035.         XtManageChild(dialog);
  2036.  
  2037.         context = XtWidgetToApplicationContext (w);
  2038.         while (answer == RET_NONE || XtAppPending(context)) {
  2039.                 XtAppProcessEvent (context, XtIMAll);
  2040.         }
  2041.         XtDestroyWidget(dialog);  /* blow away the dialog box and shell */
  2042.         return answer;
  2043.   }
  2044.  
  2045. The dialog supports three buttons, which are set to call the same
  2046. function when tickled by the user.  The variable answer is set when
  2047. the user finally selects one of those choices:
  2048.  
  2049.   void response(w, client, call)
  2050.         Widget          w;
  2051.         XtPointer client;
  2052.         XtPointer call;
  2053.   {
  2054.   int *answer = (int *) client;
  2055.   XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *) call;
  2056.         switch (reason->reason) {
  2057.         case XmCR_OK:
  2058.                 *answer = RET_YES;    /* some #define value */
  2059.                 break;
  2060.         case XmCR_CANCEL:
  2061.                 *answer = RET_NO; 
  2062.         break;
  2063.         case XmCR_HELP:
  2064.                 *answer = RET_HELP;
  2065.                 break;
  2066.         default:
  2067.                 return;
  2068.         }
  2069. }
  2070.  
  2071. and the code unwraps back to the point at which an answer was needed and
  2072. continues from there.
  2073.  
  2074. [Thanks to Dan Heller (argv@sun.com); further code is in Dan's R3/contrib
  2075. WidgetWrap library. 2/91]
  2076.  
  2077. ----------------------------------------------------------------------
  2078. Subject: 44. How do I simulate a button press/release event for a widget?
  2079. ----------------------------------------------------------------------
  2080.  
  2081. You can do this using XSendEvent(); it's likely that you're not setting
  2082. the window field in the event, which Xt needs in order to match to the widget
  2083. which should receive the event.
  2084.  
  2085.  If you're sending events to your own application, then you can use 
  2086. XtDispatchEvent() instead. This is more efficient than XSendEvent() in that you
  2087. avoid a round-trip to the server.
  2088.  
  2089. Depending on how well the widget was written, you may be able to call
  2090. its action procedures in order to get the effects you want.
  2091.  
  2092. [courtesy Mark A. Horstman (mh2620@sarek.sbc.com), 11/90]
  2093.  
  2094. ----------------------------------------------------------------------
  2095. Subject: 45. How to use Fallback resources (can I specify colors)?
  2096. ----------------------------------------------------------------------
  2097.  
  2098. (Courtesy of Donna Converse, converse@x.org; 12/7/93)
  2099. See the R5 Intrinsics specification section 2.3 "Loading the 
  2100. Resource Database".   
  2101.  
  2102. Colors cannot be reliably specified in fallback resources.  The
  2103. only way you could force this to work would be to include in the
  2104. application the same algorithm that Xt uses to determine the display;
  2105. to open that display, determine if it is color, close the display;
  2106. and then set the appropriate fallback resources; and continue on
  2107. as usual.
  2108.  
  2109. The intended use of fallback resources is to provide a minimal number
  2110. of resources that will make the application usable (or at least terminate
  2111. with helpful diagnostic messages) when some problem exists in finding and 
  2112. loading the application class defaults file.
  2113.  
  2114. The application class defaults file is authored by the application
  2115. developer and can be used to specify default colors that apply only
  2116. to capable monitors.  
  2117.  
  2118. In addition, users of an Xt-based application can specify colors in
  2119. an application-specific user-specific resource file and have those
  2120. apply only to capable monitors.  The mechanism for setting this up
  2121. is introduced in R5 Xt and it is the customization resource and this
  2122. is noted in the Xt specification section 13.3.3.  Read that section,
  2123. read section 2.3, and look at this simple example for an application
  2124. whose class name is "Xmh".  (Maybe there's a tutorial about this
  2125. in one of the O'Reilly books?  Maybe I should write a book?)
  2126.  
  2127. The end-user must set the customization resource, at any point
  2128. earlier than when the Intrinsics goes to look for the application
  2129. defaults files.
  2130.  
  2131. #ifdef COLOR
  2132. Xmh.customization: -color
  2133. #endif
  2134.  
  2135. The application programmer supplies two application class defaults
  2136. files, and one has the string "-color" appended to the application
  2137. class name as the name of the file.  This file includes the other
  2138. file, and it also gives resources specific to color displays.  The
  2139. other file gives resources that generally apply.  
  2140.  
  2141. In the application class defaults file named "Xmh-color", it might say:
  2142.  
  2143. #include "Xmh"
  2144. xmh*borderColor: Red
  2145. xmh*background:     Ivory
  2146.  
  2147. and so on.  In the application class defaults file named "Xmh"
  2148. it might say:
  2149.  
  2150. ! AppDefaultsVersion should only be defined in the site-wide file
  2151. Xmh.AppDefaultsVersion:        1
  2152. Xmh.Geometry:            508x750
  2153. Xmh.ReplyInsertFilter:        cat
  2154. Xmh.SendBreakWidth:        2000
  2155.  
  2156. and so on.  The first line is a comment, and introduces another 
  2157. interesting mechanism that demonstrates how fallback resources 
  2158. can be useful in checking that the application class defaults file
  2159. is installed.  Xt will use the fallback resources only if the
  2160. application class (site-wide) defaults file is not found.  The
  2161. application itself, in this case xmh, checks the value of application
  2162. resource AppDefaultsVersion and if it is the default value, or of a
  2163. revision earlier than the application expects, it can recognize
  2164. that the correct default resources are not available and report it by 
  2165. popping up a dialog box with a message so the user can understand
  2166. what needs to be done to get these default resources.
  2167.  
  2168. The application class default files were intended to be modifiable by
  2169. a site administrator -- if you try to stuff all the default resources
  2170. into the fallback resources not only will you not have the power of the
  2171. customization resource but you might also have to tell people to edit
  2172. the source to change the default resources -- which is a disadvantage.
  2173.  
  2174. ----------------------------------------------------------------------
  2175. Subject: 46. What is the preferred way of setting the application resources?
  2176. ----------------------------------------------------------------------
  2177.  
  2178. (Courtesy of Donna Converse, converse@x.org; 1/8/94)
  2179. I advise using a site-wide application default file.
  2180.  
  2181. Advantages of using an application default file:
  2182.  
  2183. + The site administrator can customize your application for all users
  2184.   at the site.
  2185.  
  2186. + You can indicate in the application-defaults file which resources
  2187.   may be changed and the effect of changing them by commenting.
  2188.  
  2189. + Its an additional form of documentation for power users of your app.
  2190.   Many users create an application-specific defaults file of their own.
  2191.   Those who do usually read the site-wide application defaults file
  2192.   in order to see what's going on.  To allow user-specified defaults
  2193.   to take precedence over site-wide defaults, application developers
  2194.   should always give the loosest resource binding and use class names
  2195.   rather than instance names where possible, in the site-wide defaults file.
  2196.  
  2197. + You can supply multiple versions, each implementing different styles,
  2198.   languages, presentation arrangements, options, colors, demonstrating
  2199.   the coherence and adaptability of your application by having the user
  2200.   changing the value of their customization resource for your application.
  2201.   Application default files may include other application default files,
  2202.   making it possible to separate color customization from language
  2203.   customization, from functional customization, for example.
  2204.  
  2205.  
  2206. Disadvantages of using fallback resources for the default resources of
  2207. the application:
  2208.  
  2209. - Fallback resources were not designed with this purpose in mind.
  2210.  
  2211. - Code bloat.
  2212.  
  2213. - Users and site administrators will be tempted to edit your source
  2214.   in order to figure out what resources you have set and to make their
  2215.   own changes, making things messy and difficult for them when it
  2216.   comes time to update their sources.
  2217.  
  2218. - Anyone can override all of your default resources by supplying their
  2219.   own application default file, often inexplicably breaking your app.
  2220.  
  2221. - You're not taking advantage of one of the most powerful features of
  2222.   the X toolkit -- it's provision for end-users to customize applications.
  2223.  
  2224.  
  2225. > I read where fallback
  2226. > resources should be a minimum to get the application running or to
  2227. > display an error if the application defaults cannot be loaded.  Any
  2228. > idea what a "minimum" is :-) ?
  2229.  
  2230. The X Consortium's mail application, xmh, has an application defaults
  2231. file aptly named Xmh.  If you remove this file, it's fallback resources
  2232. are used.  In that case it pops up a dialog box warning you that the
  2233. application functionality will probably not work because the application
  2234. defaults file is missing.  This same design can be used as a versioning
  2235. check on the application defaults file, when one is used, and xmh implements
  2236. that as well -- so you can update your application and the app-defaults
  2237. file and implement a versioning check, and report it when the site
  2238. administrator failed to install your application correctly.
  2239.  
  2240. Now, try using the X Consortium's calculator application, xcalc, without
  2241. its application defaults file.  Nothing works at all, and, it doesn't say
  2242. why, so the application is worthless and uncommunicative without its
  2243. application defaults file.
  2244.  
  2245. So a minimum is to report that the application defaults file is missing,
  2246. or, if you have a simple application, to have the minimum functionality
  2247. in place with no decorative resources set.
  2248. -- 
  2249. Pete Ware                    ware@cis.ohio-state.edu
  2250. CIS Dept, Ohio State University            w/ (614) 292-7318
  2251. 228 Bolz Hall, 2036 Neil Ave.            h/ (614) 538-0965
  2252. Columbus, OH 43210
  2253.